﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments.ScheduleOverrides;

namespace YaAppoint.Web.Controllers
{
    public class ScheduleOverrideController(IScheduleOverrideAppService scheduleOverrideAppService) : AbpController
    {
        private readonly IScheduleOverrideAppService _scheduleOverrideAppService = scheduleOverrideAppService;

        /// <summary>
        /// 左侧导航树形数据
        /// </summary>
        [HttpGet("/api/schedule-override/get-tree-data")]
        public async Task<IActionResult> GetTreeData(Guid? depId)
        {
            return new JsonResult(await _scheduleOverrideAppService.GetTreeData(depId));
        }

        /// <summary>  7
        /// 获取列表
        /// </summary>
        [HttpGet("/api/schedule-override/get-list")]
        public async Task<IActionResult> GetList(Guid deviceid)
        {
            return new JsonResult(await _scheduleOverrideAppService.GetList(deviceid));
        }

        /// <summary>
        /// 提交新建
        /// </summary>
        [HttpPost("/api/schedule-override/submit-create")]
        public async Task<IActionResult> SubmitCreat([FromBody]CreateScheduleOverrideDto dto)
        {
            return new JsonResult(await _scheduleOverrideAppService.SubmitCreat(dto));
        }

        
        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet("/api/schedule-override/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult(await _scheduleOverrideAppService.GetAsync(id));
        }

        /// <summary>
        /// 判断给定设备给定日期下是否已经存在特殊安排
        /// </summary>
        [HttpGet("/api/schedule-override/is-already-exist")]
        public async Task<IActionResult> IsAlreadyExist(Guid deviceId, DateTime date)
        {
            return new JsonResult(await _scheduleOverrideAppService.IsAlreadyExist(deviceId,date));
        }


        /// <summary>
        /// 删除
        /// </summary>
        [HttpGet("/api/schedule-override/delete")]
        public async Task<IActionResult> Delete(Guid id)
        {
            return new JsonResult(await _scheduleOverrideAppService.Delete(id));
        }
    }
}
